home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Devices and Hardware / ADB / ControlKeyPatch / ControlKeyPatch.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  4.8 KB  |  129 lines  |  [TEXT/MPS ]

  1. /*    File:        ControlKeyPatch.h
  2.     
  3.     Description: 
  4.              routines for patching the ADB manager to simulate the control
  5.             key being held down.  This file contains declarations for routines
  6.             in ControlKeyPatch.c.  These routines are for installing,
  7.             removing and calling the control key patch.
  8.  
  9.     Author:    John Montbriand
  10.  
  11.     Copyright: 
  12.             Copyright © 1999 by Apple Computer, Inc.
  13.             All rights reserved worldwide.
  14.     
  15.     Disclaimer:
  16.             You may incorporate this sample code into your applications without
  17.             restriction, though the sample code has been provided "AS IS" and the
  18.             responsibility for its operation is 100% yours.  However, what you are
  19.             not permitted to do is to redistribute the source as "DSC Sample Code"
  20.             after having made changes. If you're going to re-distribute the source,
  21.             we require that you make it clear in the source that the code was
  22.             descended from Apple Sample Code, but that you've made changes.
  23.     
  24.     Change History (most recent first):
  25.             27/8/99 created by John Montbriand
  26. */
  27.  
  28. #ifndef __CONTROLKEYPATCH__
  29. #define __CONTROLKEYPATCH__
  30.  
  31. #include <MacTypes.h>
  32. #include <DeskBus.h>
  33. #include <MixedMode.h>
  34.  
  35.     /* layout of the patch segment data */
  36. #pragma options align=mac68k
  37. typedef struct {
  38.     short branch;        /* bra.s instruction to ADB service routine */
  39.     short downbranch;    /* bra.s instruction to routine for pressing key */
  40.     short upbranch;    /* bra.s instruction to routine for releasing key */
  41.     long codedata[1];    /* remaining instructions making up segment */
  42. } ControlKeyPatchSegment;
  43. #pragma options align=reset
  44.  
  45.  
  46.     /* data variables used for storing information about the patch */
  47.     
  48. typedef struct ControlKeyPatchVars ControlKeyPatchVars;
  49. typedef ControlKeyPatchVars *ControlKeyPatchPtr;
  50.  
  51.  
  52.     /* definitions used for calling back to the segment.  They allow these
  53.        calls to be made from 68k or powerpc code.  */
  54.  
  55. typedef void (*KeyCmdCallPtr)(ControlKeyPatchPtr data);
  56.  
  57. #if TARGET_CPU_PPC
  58. typedef UniversalProcPtr KeyCmdCallUPP;
  59. enum {
  60.     uppControlKeyCommandProcInfo = kCStackBased
  61.     | RESULT_SIZE(kNoByteCode)
  62.     | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ControlKeyPatchPtr)))
  63. };
  64. #define NewControlKeyCommandUPP(theProc) NewRoutineDescriptor((ProcPtr) (theProc), uppControlKeyCommandProcInfo, kM68kISA)
  65. #define DisposeControlKeyCommandUPP(theProc) DisposeRoutineDescriptor((UniversalProcPtr) (theProc))
  66. #define CallControlKeyCommandUPP(theProc, data) CallUniversalProc((UniversalProcPtr) theProc, uppControlKeyCommandProcInfo, data)
  67. #else
  68. typedef KeyCmdCallPtr KeyCmdCallUPP;
  69. #define NewControlKeyCommandUPP(theProc) ((KeyCmdCallUPP)(theProc))
  70. #define DisposeControlKeyCommandUPP(theProc)
  71. #define CallControlKeyCommandUPP(theProc, data) ((KeyCmdCallUPP) (theProc))(data)
  72. #endif
  73.  
  74. struct ControlKeyPatchVars {
  75.         /* fields shared by the assembly code and the C code.
  76.            Their offests in this structure are important as they
  77.            are assumed by the 68k assembly. */
  78.     long command;
  79.     long downflag;
  80.     long originaljump;
  81.     long originaldata;
  82.         /* for restoring the previous adb state */
  83.     ADBAddress adbAddress;
  84.         /* the code segment and its variables */
  85.     ControlKeyPatchSegment *patchSegment;
  86.         /* for calling back to the patch */
  87.     KeyCmdCallUPP SetKeyUpHook;
  88.     KeyCmdCallUPP SetKeyDownHook;
  89.         /* for tracking the heap */
  90.     long systemPatch;
  91. };
  92.  
  93.     /* kErrNoKeyboardFound is returned by NewControlKeyPatch
  94.       or ControlKeyPatchReInstall when no keyboard can be found. */
  95. enum {
  96.     kErrNoKeyboardFound = 1324
  97. };
  98.  
  99.     /* NewControlKeyPatch installs a new patch for the control key and returns
  100.        a structure that can be used for calling and maintaining the patch.  If inSysHeap
  101.        is true, then the patch and all of it's related structures are allocated in the
  102.        system heap.  Normally, patches should be allocated in the system heap
  103.        unless it is being allocated for testing purposes. */
  104. OSErr NewControlKeyPatch(Boolean inSysHeap, ControlKeyPatchPtr *patch);
  105.  
  106.     /* DisposeControlKeyPatch removes the patch and disposes of all of the structures
  107.        associated with it.  normally, you'll never call this routine, unless you're using
  108.        the patch locally in an application. */
  109. void DisposeControlKeyPatch(ControlKeyPatchPtr patch);
  110.  
  111.     /* ControlKeyPatchReInstall should be called when the ADB table has been
  112.        re-initialized.  Normally, you'll call this routine from a patch to the
  113.        _ADBReInit trap. */
  114. OSErr ControlKeyPatchReInstall(ControlKeyPatchPtr patch);
  115.  
  116.     /* SetControlKeyDown can be called to lock down the control key.  While the
  117.        key is locked down, the control key is turned off on the keyboard. It is safe
  118.        to call this routine at interrupt time.*/
  119. void SetControlKeyDown(ControlKeyPatchPtr patch);
  120.  
  121.     /* SetControlKeyUp should be called after a call to SetControlKeyDown.
  122.       this routine unlocks the control key.  It is safe to call this routine
  123.       at interrupt time. */
  124. void SetControlKeyUp(ControlKeyPatchPtr patch);
  125.  
  126.  
  127.  
  128. #endif
  129.